package com.lancoo.answer.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.TypedValue;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatButton;

import com.lancoo.answer.model.AnswerConstant;

/**
 * 试题字体大小调整
 */
public class ExamFontSizeAdjustUtils {

    /**
     *
     * @param tv TextView
     * @param normalSize 标准大小
     */
    public static void adjustTextViewFontSize(TextView tv,int normalSize){
        if(tv==null){
            return;
        }
        Context context = tv.getContext();
        SharedPreferences sp = context.getSharedPreferences(AnswerConstant.SP_ANSWER_NAME, Context.MODE_PRIVATE);
        int fontSizeIndex = sp.getInt(AnswerConstant.SP_FONT_SIZE, 1);
        int fontSize=normalSize+(fontSizeIndex-1)*2;
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontSize);
    }

    public static void adjustWebViewFontSize(WebView webView){
        if(webView==null){
            return;
        }
        Context context = webView.getContext();
        SharedPreferences sp = context.getSharedPreferences(AnswerConstant.SP_ANSWER_NAME, Context.MODE_PRIVATE);
        int fontSizeIndex = sp.getInt(AnswerConstant.SP_FONT_SIZE, 1);
        int fontSize=100+(fontSizeIndex-1)*20;
        WebSettings settings = webView.getSettings();
        settings.setTextZoom(fontSize);
    }
}
